package com.bawei.jetpackdemo.service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.bawei.jetpackdemo.MainActivity;
import com.bawei.jetpackdemo.R;

/**
 * 定位功能：service服务中完成，不要放在activity中
 */
public class LocationActivity extends AppCompatActivity {
    private Intent mIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location);
        mIntent = new Intent(this,LocationService.class);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new  String[]{
                    "android.permission.ACCESS_COARSE_LOCATION",
                    "android.permission.ACCESS_FINE_LOCATION",
                    "android.permission.ACCESS_WIFI_STATE",
                    "android.permission.ACCESS_NETWORK_STATE",
                    "android.permission.CHANGE_WIFI_STATE",
                    "android.permission.WRITE_EXTERNAL_STORAGE"
            },101);
        }

    }
    //启动服务
    public void startService(View view) {
        startService(mIntent);


    }
    //停止服务
    public void stopService(View view) {
        stopService(mIntent);
    }

    public void startActivity(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}